package com.duang.framework.config;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class BeanCache {

	private Map<Class<?>, List<Object>> interfaceCache = new HashMap<Class<?>, List<Object>>();
	private Map<String, Object> namedCacheMap = new HashMap<String, Object>();
	private Map<Class<?>, Object> classCaches = new HashMap<Class<?>, Object>();

	public void putNamedMap(String name, Object object) {
		namedCacheMap.put(name, object);
	}

	public Object getNamedObject(String name) {
		return namedCacheMap.get(name);
	}

	public void put(Class<?> name, Object object) {
		classCaches.put(name, object);
	}

	public Object get(Class<?> name) {
		return classCaches.get(name);
	}

	public void putInterface(Class<?> inter, Object obj) {
		List<Object> objList;
		if ((objList = interfaceCache.get(inter)) == null) {
			objList = new ArrayList<Object>(2);
			objList.add(obj);
			interfaceCache.put(inter, objList);
		} else {
			if (!objList.contains(obj))
				objList.add(obj);
		}
	}

	public List<Object> getInterface(Class<?> inter) {
		return interfaceCache.get(inter);
	}

}
